﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using umbraco.presentation.nodeFactory;

namespace CoreDataTypes.RelatedLinks.RazorModel
{
    public class Link : IHtmlString
    {
        public string Title { get; set; }
        public LinkType Type { get; set; }
        public bool NewWindow { get; set; }
        public string Data { get; set; }

        public string Target
        {
            get
            {
                return NewWindow ? "_blank" : "_self";
            }
        }
        public string Href { get { return Url; } }
        public string Url
        {
            get
            {
                string href = string.Empty;
                switch (Type)
                {
                    case LinkType.Internal:
                        href = new Node(int.Parse(Data)).NiceUrl;
                        break;
                    case LinkType.External:
                        href = Data;
                        break;
                }
                return href;

            }
        }
        #region IHtmlString Members

        public string ToHtmlString()
        {
            return string.Format("<a href=\"{0}\" target=\"{1}\"><span>{2}</span></a>", Url, Target, Title);
        }

        #endregion
    }
    public enum LinkType
    {
        Internal,
        External
    }
}
